package com.lian.helloworld.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.lian.helloworld.model.Employee;
import com.lian.helloworld.service.EmployeeManager;

@Controller
public class EmployeeAndController {
	
	@RequestMapping("/showEmployeeForm")
	public ModelAndView getEmployeeForm(){
		ModelAndView mv = new ModelAndView("employeeAdd");
		mv.addObject("employeeEntity", new Employee());
		return mv;
	}
	
	@RequestMapping("/addEmployee")
	public ModelAndView addEmployee(@ModelAttribute(value="employee") Employee employee){
		EmployeeManager manager = new EmployeeManager();
		manager.addEmployee(employee);
		ModelAndView mv = new ModelAndView("employeeList");
		mv.addObject("employeeList", manager.getEmployeeList());
		return mv;
	}
	
	
}
